<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Scans the buffer for an occurrence of a string</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="eventbuffer.readline.html">EventBuffer::readLine</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="eventbuffer.searcheol.html">EventBuffer::searchEol</a></div>
 <div class="up"><a href="class.eventbuffer.html">EventBuffer</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="eventbuffer.search" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">EventBuffer::search</h1>
  <p class="verinfo">(PECL event &gt;= 1.2.6-beta)</p><p class="refpurpose"><span class="refname">EventBuffer::search</span> &mdash; <span class="dc-title">Scans the buffer for an occurrence of a string</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-eventbuffer.search-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> 
   <span class="methodname"><strong>EventBuffer::search</strong></span>
    ( <span class="methodparam">
    <span class="type">string</span>
     <code class="parameter">$what</code>
   </span>
   [, <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$start</code>
    <span class="initializer"> = -1</span>
   </span>
   [, <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$end</code>
    <span class="initializer"> = -1</span>
   </span>
  ]] )</div>

  <p class="para rdfs-comment">
   Scans the buffer for an occurrence of the string
   <em><code class="parameter">what</code></em>
   . It returns numeric position of the string, or <strong><code>FALSE</code></strong> if the string was
   not found.
  </p>
  <p class="para">
   If the
   <em><code class="parameter">start</code></em>
   argument is provided, it points to the position at which the search should
   begin; otherwise, the search is performed from the start of the string. If
   <em><code class="parameter">end</code></em>
   argument provided, the search is performed between start and end buffer
   positions.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-eventbuffer.search-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>

     <em><code class="parameter">what</code></em>
    </dt>

    <dd>

     <p class="para">
      String to search.
     </p>
    </dd>

   
   
    <dt>

     <em><code class="parameter">start</code></em>
    </dt>

    <dd>

     <p class="para">
      Start search position.
     </p>
    </dd>

   
   
    <dt>

     <em><code class="parameter">end</code></em>
    </dt>

    <dd>

     <p class="para">
      End search position.
     </p>
    </dd>

   
  </dl>

 </div>

 <div class="refsect1 returnvalues" id="refsect1-eventbuffer.search-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns numeric position of the first occurance of the string in the
   buffer, or <strong><code>FALSE</code></strong> if string is not found.
  </p>
  <div class="warning"><strong class="warning">Warning</strong><p class="simpara">此函数可能返回布尔值
<strong><code>FALSE</code></strong>，但也可能返回等同于 <strong><code>FALSE</code></strong> 的非布尔值。请阅读 <a href="language.types.boolean.html" class="link">布尔类型</a>章节以获取更多信息。应使用
<a href="language.operators.comparison.html" class="link">===
运算符</a>来测试此函数的返回值。</p></div>
 </div>

 <div class="refsect1 examples" id="refsect1-eventbuffer.search-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-4159">
   <p><strong>Example #1 
    <span class="function"><strong>EventBuffer::search()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Count&nbsp;total&nbsp;occurances&nbsp;of&nbsp;'str'&nbsp;in&nbsp;'buf'<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">count_instances</span><span style="color: #007700">(</span><span style="color: #0000BB">$buf</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$total&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$buf</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">search</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$p</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$p&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;++</span><span style="color: #0000BB">$total</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;++</span><span style="color: #0000BB">$p</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$total</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$buf&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">EventBuffer</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$buf</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #DD0000">"Some&nbsp;string&nbsp;within&nbsp;a&nbsp;string&nbsp;inside&nbsp;another&nbsp;string"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">count_instances</span><span style="color: #007700">(</span><span style="color: #0000BB">$buf</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"str"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(3)
</pre></div>
   </div>
  </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-eventbuffer.search-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member">
    <span class="methodname"><a href="eventbuffer.searcheol.html" class="methodname" rel="rdfs-seeAlso">EventBuffer::searchEol()</a> - Scans the buffer for an occurrence of an end of line</span>
   </li>
  </ul>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="eventbuffer.readline.html">EventBuffer::readLine</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="eventbuffer.searcheol.html">EventBuffer::searchEol</a></div>
 <div class="up"><a href="class.eventbuffer.html">EventBuffer</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
